<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/font-awesome/css/font-awesome.min.css}">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/Ionicons/css/ionicons.min.css}">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/adminlte/dist/css/AdminLTE.min.css}">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect. -->
    <link rel="stylesheet" th:href="@{/adminlte/dist/css/skins/skin-blue.min.css}">

    <link rel="stylesheet" th:href="@{/bootstrap-table/bootstrap-table.css}">

    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

    <title>标椎地名地址管理系统</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <div th:replace="common/header :: header"></div>

    <div th:replace="common/menu :: menu"></div>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" >
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Page Header
                <small>Optional description</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>行政区划管理</a></li>
                <li class="active">行政区划列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content container-fluid">
            <!--<div class="row">-->
                <!--<div class="box box-info">-->
                    <!--<table id="dataTable" class="table table-hover table-responsive" style="table-layout: fixed"></table>-->
                <!--</div>-->
            <!--</div>-->

            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <div class="box-body">
                            <div id="toolbar">
                                <div class="form-inline" role="form">
                                    <div class="form-group">
                                        <label for="keyword">Keyword: </label>
                                        <input name="keyword" class="form-control" type="text" id="keyword">
                                    </div>
                                    <button id="searchBtn" type="submit" class="btn btn-primary" style="margin-left: 5px">
                                        查询
                                    </button>
                                    <a href="/Area/toadd">
                                        <button id="createBtn" type="submit" class="btn btn-info" style="margin-left: 30px">
                                            录入
                                        </button>
                                    </a>
                                    <button id="deleteBtn" type="submit" class="btn btn-danger">删除</button>
                                </div>
                            </div>
                            <table id="dataTable" class="table table-hover table-responsive"
                                   style="table-layout: fixed"></table>
                        </div>
                    </div>
                </div>
            </div>

            <!--------------------------
              | Your Page Content Here |
              -------------------------->

            <!--<table>-->
                <!--<thead>-->
                <!--<tr>-->
                    <!--<th>area_id</th>-->
                    <!--<th>area_name</th>-->
                    <!--<th>area_map</th>-->
                <!--</tr>-->
                <!--</thead>-->
                <!--<tbody>-->
                <!--<tr th:each="area:${areas}">-->
                    <!--<td th:text="${area.areaId}"></td>-->
                    <!--<td th:text="${area.areaName}"></td>-->
                    <!--<td th:text="${area.areaMap}"></td>-->
                    <!--<td><a th:href="'/Area/edit?id=' + ${area.areaId}"><i class="fa fa-pencil-square-o"></i>编辑</a></td>-->
                    <!--<td><button type="button" th:attr="onclick=|deleteArea(this, '${area.areaId}')|">删除</button></td>-->
                <!--</tr>-->
                <!--</tbody>-->
            <!--</table>-->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <div th:replace="common/footer :: footer"></div>



</div>
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 3 -->
<script th:src="@{/adminlte/bower_components/jquery/dist/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script th:src="@{/adminlte/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>

<script th:src="@{/adminlte/bower_components/fastclick/lib/fastclick.js}"></script>

<!-- AdminLTE App -->
<script th:src="@{/adminlte/dist/js/adminlte.min.js}"></script>

<script th:src="@{/adminlte/dist/js/demo.js}"></script>

<!--<script th:src="@{/js/jquery-3.4.1.min.js}"></script>-->

<script th:src="@{/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/bootstrap-table/locale/bootstrap-table-zh-CN.js}"></script>

<script th:src="@{/adminlte/bower_components/layer-v3.1.1/layer/layer.js}"></script>

<script>
    // function deleteArea(elem,id) {
    //     $.ajax({
    //         url:"/Area/delete?id=" + id,
    //         method:"delete",
    //         success:function (data) {
    //             if (data == true){
    //                 $(elem).parent().parent().remove()
    //             }else {
    //                 console.log("失败");
    //             }
    //         },
    //         fail:function (data) {
    //             console.log(data);
    //         }
    //     })
    //
    // }

    $('#dataTable').bootstrapTable({
        method: 'get',
        url: "/Area/api/search",
        // toolbar: '#toolbar',
        // striped: true,
        dataField: "areas",
        pageNumber: 1,
        pagination: true,
        queryParamsType: 'limit',
        queryParams: queryParams,
        sidePagination: 'server',
        pageSize: 10,
        pageList: [10, 20, 50, 100],
        // search: true,
        showRefresh: false,
        clickToSelect: true,
        toolbarAlign: 'left',
        buttonsAlign: 'right',
        toolbar: '#toolbar',
        showColumns: true,
        columns: [
            {
                title: '全选',
                field: 'select',
                checkbox: true,
                width: 25,
                align: 'center',
            },
            {
                title: 'ID',
                field: 'areaId',
                visible: false,
                width: 160
            },
            {
                title: 'Edit',
                width: 50,
                formatter: function (value, row, index, field) {
                    return [
                        '<a class="edit ml10" href="javascript:void(0)" title="Edit">',
                        '<i class="glyphicon glyphicon-edit"></i>',
                        '</a>',
                    ].join('');
                },
                events: {
                    'click .edit': function (e, value, row, index) {
                        window.location.href = '/Area/edit?id=' + row.areaId;
                    }
                },
                align: 'center'
            },
            {
                title: 'AreaName',
                field: 'areaName',
                width: 160,
                align: 'center'
            },
            {
                title: 'AreaMap',
                width: 50,
                formatter: function (value, row, index, field) {
                    return [
                        '<a class="map ml10" href="javascript:void(0)" title="Map">',
                        '<i class="glyphicon glyphicon-paperclip"></i>',
                        '</a>',
                    ].join('');
                },
                events: {
                    'click .map': function (e, value, row, index) {
                        window.location.href = '/Area/areaMap?areaName=' + row.areaName;
                    }
                },
                align: 'center'
            }
        ],
        locale: 'zh-CN',
        responseHandler: function (data) {
            return data;
        }
    });

    function queryParams(params) {
        return {
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            keyword: $('#keyword').val()
        }
    }

    $("#deleteBtn").click(function () {
        var selects = $('#dataTable').bootstrapTable('getSelections');
        console.log(selects);
        //var str = JSON.stringify(selects);
        layer.confirm("确定删除吗",{icon: 3,title: "提示"}, function(index) {
            for (var i = 0; i <selects.length; i++) {
                //alert(selects[i].areaId);
                $.ajax({
                    url: "/Area/delete?id=" + selects[i].areaId,
                    method: "delete",
                    success: function (data) {
                        if (data == true) {
                            // $(elem).parent().parent().remove()
                            layer.msg("操作成功", {time: 700}, function () {
                                $('.selected').remove();
                                console.log("成功")
                            });
                        } else {
                            console.log("失败");
                        }
                    },
                    fail: function (data) {
                        console.log(data);
                    }
                })
            }
        });
    });

    $("#searchBtn").click(function () {
        //$('#dataTable').bootstrapTable('refresh');
        var input = $('#keyword').val()
        // $('table tbody tr').hide()
        //     .filter(":contains('" + ($('#keyword').val()) + "')")
        //     .show();
        $('#dataTable').bootstrapTable('refresh', {
            url: "/Area/api/searchLike?areaName=" + input
        });
    });

</script>



<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. -->
</body>
</html>